<?php
class fwConverter
{
	public static function text2JSString($str)
	{
		return addslashes(str_replace(array("\r\n", "\r", "\n", "«"), array('', '', '', '«!'), $str));
	}
	
	public static function data2url($data)
	{
		if(is_array($data))
		{
			$str = '';
			foreach ($data as $name => $value)
			{
				$str.='&'.urlencode($name).'='.urlencode(fwConverter::data2url($value));
			}
			return substr($str, 1);
		}
		else 
		{
			return $data;
		}
	}
	
	public static function url2data($url)
	{
		if(strpos($url, '=')===false && strpos($url, '&')===false)
		{
			return $url;
		}
		$datas = array();
		$tmp = explode('&', $url);
		foreach ($tmp as $data)
		{
			list($name, $value) = explode('=', $data);
			$datas[urldecode($name)] = fwConverter::url2data(urldecode($value));
		}
		return $datas;
	}
}
?>